<?php

class Giaovien extends MY_Admin
{
	// Protected or private properties
	protected $_template;
	
	// Constructor
	public function __construct()
	{
		parent::__construct();

		$this->load->module_model('admin', 'giaovien_model', 'giaovien');
		$this->load->module_language('admin', 'general');
		$this->load->module_language('admin', 'giaovien');
		$this->user = $this->access->get_user();
		$this->load->helper('url'); 
	}

	// Public methods
	public function index() 
	{
		$this->access->restrict('Admin.Giaovien.Index');
		$data['ItemID'] = 'User';
		$data['title'] = 'Danh sách Giáo viên';
		$data['description'] = 'Quản lý danh sách Giáo viên';
		$this->access->restrict();
		$this->load->library('pagination');
		
		$config = array();
		$config['base_url'] = base_url().'admin/giaovien/index';
		$config['total_rows'] = $this->giaovien->count_all_giaovien();
		$config['per_page'] = 100;
		$config['uri_segment'] = 4;
		$config['num_links'] = 5;
		$config['first_link'] = 'Đầu tiên';
        $config['last_link'] = 'Cuối cùng';
        $config['next_link'] = 'Tiếp theo';
        $config['prev_link'] = 'Lùi lại';
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(4))? $this->uri->segment(4):0;
		$data['sotrang']	=	$this->uri->segment(4);
		$data['hocviens'] = $this->giaovien->get_all_giaovien($config['per_page'], $page);
		$data['links'] = $this->pagination->create_links();		
		
		$this->_template['page']	= 'giaovien/list';
		$this->system_library->load($this->_template['page'], $data, TRUE);
	}
	
	public function search()
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Tìm kiếm thông tin';
		$data['search_keyword'] = trim($this->input->post('keyword', TRUE));
		if($data['search_keyword']!=='')
		{
			$data['result'] = $this->giaovien->search_data($data['search_keyword']);
			
				$this->_template['page']	= 'giaovien/result';
				$this->system_library->load($this->_template['page'], $data, TRUE);
			
			
		}
		else
		{
			redirect('admin/giaovien', 'refresh');
		}
	}	
	
	public function enable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->giaovien->change_status_giaovien($id,1);
		redirect('admin/giaovien', 'refresh');
		
	}
	public function disable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->giaovien->change_status_giaovien($id,0);
		redirect('admin/giaovien', 'refresh');
	}
}

/* End of file giaovien.php */